package com.asdhawaii.otello.players;

import java.util.ArrayList;
import java.util.List;
import com.asdhawaii.otello.board.Move;
import com.asdhawaii.otello.board.Square;
import com.asdhawaii.otello.board.SquareContents;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import org.junit.Test;

/**
 * Tests the Level 0 AI.
 * 
 * @author Branden Ogata
 *
 */

public class TestLevel0Ai extends TestAbstractOtelloAi
{
  /**
   * Tests that the Level 0 AI behaves as expected.
   * 
   */
  
  @Test
  public void test()
  {
    Level0Ai ai = new Level0Ai(SquareContents.BLACK);
    
    // Test with starting board
    Square[][] board = createStartingBoard();
    
    List<Move> validMoves = new ArrayList<Move>();
    validMoves.add(new Move(4, 2));
    validMoves.add(new Move(5, 3));
    validMoves.add(new Move(3, 5));
    validMoves.add(new Move(2, 4));
    
    assertTrue("Selects valid move", validMoves.contains(ai.getMove(board, validMoves)));
    
    // Test board with only one valid move
    board[4][2].setContents(SquareContents.BLACK);
    board[5][3].setContents(SquareContents.BLACK);
    board[3][5].setContents(SquareContents.BLACK);
   
    validMoves.clear();
    validMoves.add(new Move(2, 4));
    
    assertTrue("Selects only valid move", validMoves.contains(ai.getMove(board, validMoves)));
    
    // Test board with no valid moves
    board[2][4].setContents(SquareContents.BLACK);
    
    validMoves.clear();
    
    assertFalse("Selects null without valid move", 
                validMoves.contains(ai.getMove(board, validMoves)));    
  }
}